package middleware

import "github.com/gin-gonic/gin"

func CustomIPMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		remoteIP := c.Request.Header.Get("X-Real-IP")
		if remoteIP == "" {
			remoteIP = c.Request.Header.Get("X-Forwarded-For")
		}
		if remoteIP != "" {
			c.Set("remote_ip", remoteIP)
		} else {
			c.Set("remote_ip", c.ClientIP())
		}
		c.Next()
	}
}
